home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / standards / sgml / nist / parse1 / dtdnotat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-13  |  8.0 KB  |  238 lines

  1. /* National Institute of Standards and Technology (NIST)
  2. /* National Computer System Laboratory (NCSL)
  3. /* Office Systems Engineering (OSE) Group
  4. /* ********************************************************************
  5. /*                            D I S C L A I M E R
  6. /*                              (March 8, 1989)
  7. /*  
  8. /* There is no warranty for the NIST NCSL OSE SGML parser and/or the NIST
  9. /* NCSL OSE SGML parser validation suite.  If the SGML parser and/or
  10. /* validation suite is modified by someone else and passed on, NIST wants
  11. /* the parser's recipients to know that what they have is not what NIST
  12. /* distributed, so that any problems introduced by others will not
  13. /* reflect on our reputation.
  14. /* 
  15. /* Policies
  16. /* 
  17. /* 1. Anyone may copy and distribute verbatim copies of the SGML source
  18. /* code as received in any medium.
  19. /* 
  20. /* 2. Anyone may modify your copy or copies of SGML parser source code or
  21. /* any portion of it, and copy and distribute such modifications provided
  22. /* that all modifications are clearly associated with the entity that
  23. /* performs the modifications.
  24. /* 
  25. /* NO WARRANTY
  26. /* ===========
  27. /* 
  28. /* NIST PROVIDES ABSOLUTELY NO WARRANTY.  THE SGML PARSER AND VALIDATION
  29. /* SUITE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
  30. /* EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  32. /* THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS
  33. /* WITH YOU.  SHOULD THE SGML PARSER OR VALIDATION SUITE PROVE DEFECTIVE,
  34. /* YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  35. /* 
  36. /* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL NIST BE LIABLE FOR
  37. /* DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL,
  38. /* INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  39. /* INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
  40. /* BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
  41. /* FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY
  42. /* NIST) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF
  43. /* SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  44. */
  45.  
  46. /************************************************************************/
  47. /*   TITLE:          SGML PARSER                                        */
  48. /*   SYSTEM:         DTD PROCESSOR                                      */
  49. /*   SUBSYSTEM:                                                         */
  50. /*   SOURCE FILE:    DTDNOTAT.C                                         */
  51. /*   AUTHOR:         Jim Heath                                          */
  52. /*                                                                      */
  53. /*   DATE CREATED:                                                      */
  54. /*   LAST MODIFIED:                                                     */
  55. /*                                                                      */
  56. /*                  REVISIONS                                           */
  57. /*   WHEN      WHO            WHY                                       */
  58. /************************************************************************/
  59. #include <stdio.h>
  60. #include <setjmp.h>
  61. #include <memory.h>
  62. #include "qntyset.h"
  63. #include "dtd.h"
  64. #include "dtdfncs.h"
  65. #include "dtdglbl.h"
  66. #include "dtddefs.h"
  67. #define MAXNOTAT 10
  68. static char notatenames [MAXNOTAT][NAMELEN + 1];
  69. static int count = 0;
  70. /* ============================================================ */
  71. int donotation()
  72. {
  73.    int j;
  74.    char *nptr;
  75.    if ((j = INPPS()) == EOF)
  76.       terminate(1, "EOF found in ATTLIST declaration");
  77.    if (j < 1)
  78.       syntxerr("Expected PS+ at this point");
  79.    ADDCHAR(SPACE);
  80.    if (count >= MAXNOTAT)
  81.       terminate(1, "internal overflow of notation names");
  82.    nptr = notatenames[count];
  83.    if((j = INPNAME(&nptr, NAMELEN, TOUPPER)) == EOF)
  84.       terminate(1, "EOF found in NOTATION declaration");
  85.    ADDSTRING(notatenames[count++]);
  86.    for (j = 0; j < (count - 1); j++)  {
  87.       if (count == 1)
  88.          break;
  89.       if (strcmp(notatenames[count-1], notatenames[j]) == 0)
  90.          syntxerr("notation name can be specified only once in DTD");
  91.    }
  92.    if ((j = INPPS()) == EOF)
  93.       terminate(1, "EOF found in ATTLIST declaration");
  94.    if (j < 1)
  95.       syntxerr("Expected PS+ at this point");
  96.    ADDCHAR(SPACE);
  97.    inpextrnlID();
  98. }
  99. /* ============================================================ */
  100. void inpextrnlID()
  101. {
  102.    char idtype[NAMELEN + 1], *nptr = idtype;
  103.    if( INPNAME(&nptr, NAMELEN, TOUPPER) == EOF)
  104.       terminate(1, "EOF found while processing external identifier");
  105.    ADDSTRING(idtype);
  106.    if (strcmp(idtype, "SYSTEM") == 0)
  107.       dosystem(NO);
  108.    else if (strcmp(idtype, "PUBLIC") == 0)
  109.       dopublic(NO);
  110.    else syntxerr("Expected 'PUBLIC' or 'SYSTEM'");
  111. }
  112. /* ============================================================ */
  113. void dosystem(eflag)
  114. int eflag;
  115. {
  116.    int j, flag, len = 0;
  117.  
  118.    if ((j = INPPS()) == EOF)
  119.       terminate(1, "EOF found in NOTATION declaration");
  120.    ADDCHAR(SPACE);
  121.    if ((j = jgetc()) == EOF)
  122.       terminate(1, "EOF found in NOTATION declaration");
  123.    ADDCHAR(j);
  124.    if (j == MDC) {
  125.       if (eflag)
  126.          jungetc(j);
  127.       return;
  128.    }
  129.    if ((j == LIT) || (j == LITA))
  130.       flag = j;
  131.    else {
  132.       if (eflag == YES) {
  133.          jungetc(j);
  134.          return;
  135.       }
  136.       syntxerr("expected LIT or LITA");
  137.    }
  138.    while((j = jgetc()) != flag) {
  139.       if (++len > LITLEN)
  140.          syntxerr("system identifier exceeds LITLEN");
  141.       if (j == EOF)
  142.          terminate(1, "EOF found while inputting minimum literal");
  143.       ADDCHAR(j);
  144.    }
  145.    ADDCHAR(j);
  146.    if ((j = INPPS()) == EOF)
  147.       terminate(1, "EOF found in NOTATION declaration");
  148.    if (eflag == YES)
  149.       return;
  150.    j = jgetc();
  151.    ADDCHAR(j);
  152.    if (j != MDC)
  153.       syntxerr("Expected MDC following system identifier");
  154. }
  155. /* ============================================================ */
  156. void dopublic(eflag)
  157. int eflag;
  158. {
  159.    int j, flag;
  160.    char pubidentifier[LITLEN + 1];
  161.  
  162.    if ((j = INPPS()) == EOF)
  163.       terminate(1, "EOF found in NOTATION declaration");
  164.    ADDCHAR(SPACE);
  165.    if ((j = jgetc()) == EOF)
  166.       terminate(1, "EOF found in NOTATION declaration");
  167.  
  168.    ADDCHAR(j);
  169.    if ((j == LIT) || (j == LITA))
  170.       flag = j;
  171.    else
  172.       syntxerr("expected LIT or LITA");
  173.  
  174.    memset(pubidentifier, '\0', sizeof(pubidentifier));
  175.    getminimumliteral(flag, pubidentifier, LITLEN );
  176.    dosystem(eflag);
  177. }
  178. /* ============================================================ */
  179. void getminimumliteral(flag, buffer, len)
  180. int flag;
  181. char *buffer;
  182. int len;
  183. {
  184.    int j, compress = OFF, jlen = 0;
  185.  
  186.    while (1) {
  187.       j = jgetc();
  188.       if (j == EOF)
  189.          terminate(1, "EOF found while inputting minimum literal");
  190.       if (j == flag){
  191.          ADDCHAR(j);
  192.          return;
  193.       }
  194.       if (j == RS)
  195.          continue;
  196.       if ((j == SPACE) || (j == RE)) {
  197.          if (compress == ON)
  198.             continue;
  199.          compress = ON;
  200.          if (++jlen > len)
  201.             syntxerr("LITLEN has been exceeded in minimum literal");
  202.          *buffer++ = j;
  203.          ADDCHAR(j);
  204.          continue;
  205.       }
  206.       compress = OFF;
  207.       if (++jlen > len)
  208.          syntxerr("LITLEN has been exceeded in minimum literal");
  209.       *buffer++ = j;
  210.       ADDCHAR(j);
  211.       if (ISALNUM(j))
  212.          continue;
  213.       if (isspcl(j))
  214.          continue;
  215.       syntxerr("illegal character in minimum literal");
  216.    }
  217. }
  218. /* ============================================================ */
  219. void cknotation(name)
  220. char *name;
  221. {
  222.    int j;
  223.    for (j = 0; j < count; j++) {
  224.       if (strcmp(name, notatenames[j]) == 0)
  225.          return;
  226.    }
  227.    printf("\n\nERROR:\n\n");
  228.    printf("\'%s\' was used as notation name in an ATTLIST but -\n", name);
  229.    printf("no notation declaration for \'%s\' was found\n", name);
  230.    errflag = 1;
  231. }
  232. /* ============================================================ */
  233. /* ============================================================ */
  234. /* ============================================================ */
  235. /* ============================================================ */
  236. /* ============================================================ */
  237. /* ============================================================ */
  238.